package com.kwin.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class LoginServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=UTF-8");
        String client_randomNum = req.getParameter("randomNum");
        String session_randomNum = (String) req.getSession().getAttribute("randomNum");

        if (client_randomNum == null || session_randomNum == null || !client_randomNum.equals(session_randomNum)) {
            resp.getWriter().write("验证码错误");
            return;
        }

        resp.sendRedirect("/site/success.jsp");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
